{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Move Zeros\n",
    "\n",
    "[The Original Question](https://mp.weixin.qq.com/s/__VwKqqeRUqQl_NaQXoYGQ)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question\n",
    "\n",
    "Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example\n",
    "\n",
    "```{text}\n",
    "Input: [0,1,0,3,12]\n",
    "Output: [1,3,12,0,0]\n",
    "```\n",
    "\n",
    "You must do this in-place without making a copy of the array.\n",
    "Minimize the total number of operations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 1, 3, 4, 0, 0, 0, 0, 0, 0]\n"
     ]
    }
   ],
   "source": [
    "class Solution:\n",
    "    def moveZeros(self, nums: list):\n",
    "        counts = nums.count(0)\n",
    "        k = 0\n",
    "        while k < len(nums):\n",
    "            if nums[k] == 0:\n",
    "                nums.remove(nums[k])\n",
    "                pass\n",
    "            else:\n",
    "                k += 1\n",
    "                pass\n",
    "            pass\n",
    "        for k in range(counts):\n",
    "            nums.append(0)\n",
    "            pass\n",
    "        pass\n",
    "    \n",
    "    pass\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    nums = [0, 0, 0, 2, 0, 1, 3, 4, 0, 0]\n",
    "    Solution().moveZeros(nums)\n",
    "    print(nums)\n",
    "    pass"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
